package com.android.sama;

import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class MainActivity extends Activity implements OnClickListener{
	//Method name
	  
    final static ArrayList<HashMap<String, ?>> mList = new ArrayList<HashMap<String, ?>>();
    static{
    HashMap<String, Object> mrow  = new HashMap<String, Object>();
    mrow.put("Title", "Search DTO");
    mrow.put("Icon",R.drawable.product);
    mrow.put("Define","Search product information by Barcode!");
    mList.add(mrow);
    
  
    mrow=new HashMap<String, Object>();
    mrow.put("Title", "Order");
    mrow.put("Icon",R.drawable.order);
    mrow.put("Define","View all order");
    mList.add(mrow);
    
    mrow=new HashMap<String, Object>();
    mrow.put("Title", "User");
    mrow.put("Icon",R.drawable.usericon);
    mrow.put("Define","Manager user");
    mList.add(mrow);
    mrow=new HashMap<String, Object>();
    mrow.put("Title", "Order");
    mrow.put("Icon",R.drawable.usericon);
    mrow.put("Define","View all order");
    mList.add(mrow);
    
    }

	ListView lv;
	ImageButton productBt,financeBt,settingBt,searchBt;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        lv=(ListView)findViewById(R.id.listView1);
       SimpleAdapter  ad = new SimpleAdapter (this,mList, 
        			R.layout.mainmenu, new String[]{"Icon","Title","Define"},new int[]{R.id.Icon,R.id.Title,R.id.define} ); 
        lv.setAdapter(ad);
        lv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position,
					long id) {
				// TODO Auto-generated method stub
				 Intent in;
				switch(position)
				{
				case 0: in=new Intent(getApplicationContext(),searchProduct.class);
						startActivity(in);
						break;
				
				}
			}
        	
		});
      
        
    }
   
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
       try{
        switch (item.getItemId()) {
        case R.id.menu_settings:            
            startActivity(new Intent(this,setting.class));
            return true;        
        default:
            return super.onOptionsItemSelected(item);
        }
       }catch(Exception e){
         return false;
       }
    }
	@Override
	public void onClick(View v) {
	
    
	}
}
